package kr.hkit.info.powerjava.ch25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class ParseURLExample {

	public static void main(String[] args) throws MalformedURLException {
		URL myUrl = new URL ("http://www.hkit.kr/BBS/msView.php?tId=epilogue&boIdx=112&field=&search=");
		System.out.printf("protocol =%s%n",myUrl.getProtocol());
		System.out.printf("authority =%s%n",myUrl.getAuthority());
		System.out.printf("host =%s%n",myUrl.getHost());		
		System.out.printf("port =%s%n",myUrl.getPort());
		System.out.printf("Path =%s%n",myUrl.getPath());		
		System.out.printf("Query =%s%n",myUrl.getQuery());
		System.out.printf("FileName =%s%n",myUrl.getFile());
		System.out.printf("ref =%s%n",myUrl.getRef());
		BufferedReader br=null;
		try {
			br = new BufferedReader(new InputStreamReader(myUrl.openStream()));
			String line;
			while((line = br.readLine()) != null){
				System.out.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if(br != null) try {br.close();} catch (Exception e) {}
		}
	}
}

